<template>
  <div class="h-10 w-1/1 all">
    <div class="lists" ref="scrollViewRef">

      <div class="left">
        <div class="title">
          商品销量榜Top10
        </div>
        <div style="flex: 1;height: 100%;display: flex;flex-direction: column;">
          <div class="card" v-for="(item, index) in firstList" :key="index" style="flex: 1;">
            <div style="font-size:calc(100vw * 25 / 1920);font-weight: bold;">No.{{ index + 1 }}</div>
            <img v-if="item.shop_pic" :src="item.shop_pic" alt="">
            <img v-else src="../assets/imgs/moren.webp" alt="">
            <div class="card-right">
              <div class="tit">
                {{ item.shop_name }}
              </div>
              <div class="card-center">
                <div class="s1">销量</div>
                <div class="s1">下单GMV</div>
              </div>
              <div class="card-center">
                <div class="s2">{{ item.xl }}</div>
                <div class="s3">{{ item.je }}</div>
              </div>
            </div>
          </div>
        </div>

      </div>




      <div class="right" ref="listRef">
        <div class="r-top">
          <div class="r-top-l">商品</div>
          <div class="r-top-r">
            <div>销量</div>
            <div>下单GMV</div>
          </div>
        </div>
        <div class="r-bot" v-for="(item, index) in twoList" :key="index" style="flex: 1;">
          <div class="r-bot-l">
            <div style="font-size: calc(100vw * 20 / 1920);font-weight: bold;width: 20%; text-align: center;">No.{{
              index+4 }}</div>
            <div class="r-bot-l" style="flex: 1;">
              <img v-if="item.shop_pic" :src="item.shop_pic" alt="">
              <img v-else src="../assets/imgs/moren.webp" alt="">
              <div>{{ item.shop_name }}</div>
            </div>
          </div>
          <div class="r-bot-r">
            <div class="s11">{{ item.xl }}</div>
            <div class="s22">{{ item.je }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onBeforeMount, onMounted, onBeforeUnmount, nextTick } from "vue";
import { getshopList } from '../api/api'

const firstList = ref([]) //前三名
const twoList = ref([])
let auto = null;



onMounted(() => {
  loadData()
  auto = setInterval(() => {
    loadData()
  }, 10000);
})

const loadData = async () => {
  let res = await getshopList();
  const arr = res.data.data
  twoList.value = []
  firstList.value = []
  twoList.value = arr.splice(3)
  firstList.value = arr
};


onBeforeUnmount(() => {
  //离开页面清理定时器
  intervalId && clearInterval(auto);
});


</script>

<style lang="scss" scoped>
.all {
  width: 100%;
  background-color: #091432;
  display: flex;

  .lists {
    flex: 1;
    width: 100%;
    display: flex;

    .left {
      width: 40%;
      display: flex;
      flex-direction: column;

      .title {
        margin-bottom: 0.625rem;
        // font-size: 1.25rem;
        font-size: calc(100vw * 30 / 1920);
        font-weight: bold;
      }

      .card {
        margin: 5px 0;
        width: 100%;
        background-color: #000;
        padding: 0.625rem;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        border-radius: 0.625rem;

        .card-right {
          flex: 1;
          margin-left: 0.625rem;
          display: flex;
          flex-direction: column;

          .card-center {
            // margin: 0.625rem 0;
            display: flex;
            align-items: center;
            justify-content: space-between;

            .s1 {
              // font-size: 0.875rem;
              font-size: calc(100vw * 14 / 1920);
              font-weight: bold;
              color: #0b34a5;
            }

            .s2 {
              font-weight: bold;
            }

            .s3 {
              color: #c47845;
              font-weight: bold;
            }
          }

          .tit {
            // font-size: 1.25rem;
            font-size: calc(100vw * 20 / 1920);
            font-weight: bold;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 1;
            -webkit-box-orient: vertical;
          }
        }

        img {
          // width: 5rem;
          width: calc(100vw * 80 / 1920);
          // height: 5rem;
          height: calc(100vw * 80 / 1920);
          border-radius: 0.625rem;
          object-fit: cover
        }
      }
    }

    .right {
      // margin-top: 5%;
      flex: 1;
      padding: 0.625rem;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;

      .r-top {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        // margin-bottom: 1.25rem;

        .r-top-l {
          width: 60%;
          // font-size: 1rem;
          font-size: calc(100vw * 14 / 1920);
          color: #2e51b3;
          font-weight: bold;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 1;
          -webkit-box-orient: vertical;
        }

        .r-top-r {
          flex: 1;
          // font-size: 1rem;
          font-size: calc(100vw * 16 / 1920);
          color: #2e51b3;
          font-weight: bold;
          display: flex;
          align-items: center;

          .s1 {
            color: #fff;
            font-weight: bold;
          }

          .s2 {
            color: #c47845;
            font-weight: bold;
          }

          div {
            flex: 1;
            margin: 0 0.625rem;
            text-align: center;
          }
        }
      }

      .r-bot {
        margin: 0.3125rem 0;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .r-bot-l {
          width: 60%;
          display: flex;
          align-items: center;
          // font-size: 0.875rem;
          font-size: calc(100vw * 12 / 1920);
          font-weight: bold;

          img {
            // width: 3.75rem;
            // height:3.75rem;
            width: calc(100vw * 40 / 1920);
            height: calc(100vw * 40 / 1920);
            border-radius: 0.625rem;
            margin-right: 0.625rem;
            object-fit: cover
          }
        }

        .r-bot-r {
          flex: 1;
          // font-size: 1rem;
          font-size: calc(100vw * 16 / 1920);
          color: #2e51b3;
          font-weight: bold;
          display: flex;
          align-items: center;

          .s11 {
            color: #fff;
          }

          .s22 {
            color: #c47845;
          }

          div {
            flex: 1;
            margin: 0 0.625rem;
            text-align: center;
          }
        }
      }
    }
  }
}
</style>
